Hello,
string textstr ="ABC, sections 3.3.1.9, 3.3.7.1, 3.3.7.2, 3.3.9.5, 3.3.9.6.1, 3.3.9.6.2, 3.3.9.6.3, 3.3.9.6.4, 3.3.9.6.5, 3.3.12.1, 3.3.12.2, and 3.3.13.1 and DEF, sections 7.7.4.4 and 8.5.5." => "3.3.1.9, 3.3.7.1, 3.3.7.2, 3.3.9.5, 3.3.9.6.1, 3.3.9.6.2, 3.3.9.6.3, 3.3.9.6.4, 3.3.9.6.5, 3.3.12.1, 3.3.12.2, and 3.3.13.1"
//string textstr ="DEF, sections 7.7.4.2 and 8.2.4 and ABC, sections 3.3.9.2 and 3.3.9.3." => "3.3.9.2 and 3.3.9.3"
//string textstr ="ABC, section 3.3.7.2 and DEF, sections 3.6.2.4, 7.5.2.6, 7.5.2.8, and 7.5.2.9." => "3.3.7.2"
//string textstr ="DEF, section 3.6.2 and ABC, section 3.3.1.1." => "3.3.1.1"
//string textstr ="DEF, section 7.7.3.4 and ABC, section 3.3.1.9." => "3.3.1.9"
//string textstr ="ABC, section 4.3.1." => "4.3.1"
Regexp line = regexp2 "ABC, sections*([^and]*)([and]*)([^and]*)"
if (line textstr) {
print textstr[match 0] "(0)\n" // whole match
}
EHcnck - Wed Jan 08 22:32:00 EST 2014 |
Re: regular exp help needed Hi Ehcnck,
I think the following does what you need it to.
Regexp line = regexp2 "ABC, (section ([0-9.]*[0-9])|sections ( *[0-9.]*[0-9][ ,]*(and *[0-9.]*[0-9])*)*)"
if (line textstr) {
string sResult = textstr[match 1]
// Now, trim off the "section(s) " part, if necessary
sResult = (sResult[7]=='s') ? sResult[9:] : sResult[8:]
print sResult"\n"
}
Good luck.
|
Re: regular exp help needed What are you trying to do? It appears you want to turn the first line into the 2nd:
Allowing for "section" as well. First off, the following is a great resource: http://en.wikipedia.org/wiki/Regexp, where for you we find that the "?" can match zero or one time, which you want with your "s".
We notice that if there is a match, [match 0] is always the entire string, [match 1] is the first parenthesis group encountered, [match 2] is the 2nd, etc. Your result, it seems, then is textstr[match 2]. I really struggle with Regular expressions and so always stage the string in a string variable, so I can print it which drastically helps me debug it. -Louie Now perhaps what you REALLY want is to notice that this is for ABC, then recursively parse out each and every numbered section, skipping such words as "through" and "and". If so I'd be tempted to take the value between spaces, verify it appears to be a well formed section (it is all digits and periods), and use that. |
Re: regular exp help needed llandale - Thu Jan 09 15:39:06 EST 2014 What are you trying to do? It appears you want to turn the first line into the 2nd:
Allowing for "section" as well. First off, the following is a great resource: http://en.wikipedia.org/wiki/Regexp, where for you we find that the "?" can match zero or one time, which you want with your "s".
We notice that if there is a match, [match 0] is always the entire string, [match 1] is the first parenthesis group encountered, [match 2] is the 2nd, etc. Your result, it seems, then is textstr[match 2]. I really struggle with Regular expressions and so always stage the string in a string variable, so I can print it which drastically helps me debug it. -Louie Now perhaps what you REALLY want is to notice that this is for ABC, then recursively parse out each and every numbered section, skipping such words as "through" and "and". If so I'd be tempted to take the value between spaces, verify it appears to be a well formed section (it is all digits and periods), and use that. Regexp line = regexp2 "[A-Za-z0-9_]+, *sections* *((([0-9]+\\.)+[0-9]+,* *)+(and *([0-9]+\\.)+[0-9]+ *)*)"
Thank all for the help |